home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / asmutil / asm_n_z.zip / SIT.INC < prev    next >
Text File  |  1989-04-23  |  6KB  |  358 lines

  1.     .xlist
  2.  
  3. ;STANDARD macros for use in 8086 assembly work, including
  4.  
  5. ; 1) standard definitions of CR, LF, TAB, etc.
  6.  
  7. ; 2) standard BIOS and DOS interrupt numbers
  8.  
  9. ; 3) standard "extended" opcodes (far call, return, bit set/clear ops, etc.)
  10.  
  11. ; 4) structured _IF/_ELSEIF/_ELSE/_ENDIF and _WHILE/_BREAK/_AGAIN/_UNTIL
  12.  
  13. ;=============================================
  14.  
  15. ; 1) standard definitions of CR, LF, TAB, ESCAPE etc.
  16. cr    equ    0dh
  17. lf    equ    0ah
  18. tab    equ    09h
  19. escape    equ    1bh
  20. eot    equ    4
  21. ack    equ    6
  22. nak    equ    21
  23. bs    equ    08h
  24.  
  25. ;=============================================
  26.  
  27. ; 2) standard BIOS and DOS interrupt numbers
  28.  
  29. ;call to DOS function
  30. dos    macro
  31.     int    21h
  32.     endm
  33.  
  34. ;BIOS video display services
  35. video    macro
  36.     int    10h
  37.     endm
  38.  
  39. ;BIOS serial-port services
  40. serial    macro
  41.     int    14h
  42.     endm
  43.  
  44. ;BIOS device control services
  45. device    macro
  46.     int    15h
  47.     endm
  48.  
  49. ;BIOS "a key has been pressed" service
  50. keypress macro
  51.     int    9h
  52.     endm
  53.  
  54. ;BIOS "get a keystroke" services
  55. keyboard  macro
  56.     int    16h
  57.     endm
  58.  
  59. ;BIOS printer services
  60. printer macro
  61.     int    17h
  62.     endm
  63.  
  64. ;BIOS once-a-tick user services
  65. usertick macro
  66.     int    1ch
  67.     endm
  68.  
  69. ;"DOS is doing an I/O function, may be interrupted for DOS calls > 0Ch" ticker
  70. idler    macro
  71.     int    28h
  72.     endm
  73.  
  74. ;=============================================
  75.  
  76. ; 3) standard "extended" opcodes (far call, return, bit set/clear ops, etc.)
  77.  
  78. ;"far" call, jump
  79. jmpf    macro
  80.     db    0eah
  81.     endm
  82.  
  83. callf    macro
  84.     db    09ah
  85.     endm
  86.  
  87. setbits macro    target,bits
  88.     or    target,bits
  89.     endm
  90.  
  91. clrbits macro    target,bits
  92.     and    target,not(bits)
  93.     endm
  94.  
  95. tstbits macro    target,bits
  96.     test    target,bits
  97.     endm
  98.  
  99. zero    macro    register
  100.     xor    register,register
  101.     endm
  102.  
  103. ;=============================================
  104.  
  105. ; 4) structured _IF/_ELSEIF/_ELSE/_ENDIF and _WHILE/_BREAK/_AGAIN/_UNTIL
  106.  
  107. ;"negated no condition" jump
  108. jn    macro    target
  109.     jmp    short target
  110.     endm
  111.  
  112. ;"no condition" jump
  113. j    macro    target
  114.     jmp    short target
  115.     endm
  116.  
  117. ;"Double-negative" conditional jumps
  118. jnpo    macro    target
  119.     jpe    target
  120.     endm
  121.  
  122. jnpe    macro    target
  123.     jpo    target
  124.     endm
  125.  
  126. jnna    macro    target
  127.     ja    target
  128.     endm
  129.  
  130. jnnae    macro    target
  131.     jae     target
  132.     endm
  133.  
  134. jnnb    macro    target
  135.     jb    target
  136.     endm
  137.  
  138. jnnbe    macro    target
  139.     jbe     target
  140.     endm
  141.  
  142. jnnc    macro    target
  143.     jc    target
  144.     endm
  145.  
  146. jnne    macro    target
  147.     je    target
  148.     endm
  149.  
  150. jnng    macro    target
  151.     jg    target
  152.     endm
  153.  
  154. jnnge    macro    target
  155.     jge     target
  156.     endm
  157.  
  158. jnnl    macro    target
  159.     jl    target
  160.     endm
  161.  
  162. jnnle    macro    target
  163.     jle     target
  164.     endm
  165.  
  166. jnno    macro    target
  167.     jo    target
  168.     endm
  169.  
  170. jnnp    macro    target
  171.     jp    target
  172.     endm
  173.  
  174. jnns    macro    target
  175.     js    target
  176.     endm
  177.  
  178. jnnz    macro    target
  179.     jz    target
  180.     endm
  181.  
  182. jnncxz    macro    target
  183.     jcxz    target
  184.     endm
  185.  
  186. ; third-level macros to substitute jumps and jump targets
  187. ___jj    macro    cnd,target,depth
  188.     j&cnd    target&depth
  189.     endm
  190.  
  191. ___ll    macro    cnd,target,depth
  192.     loop&cnd   target&depth
  193.     endm
  194.  
  195. ___tt    macro    target,depth
  196. target&depth:
  197.     endm
  198.  
  199. ; second-level macros to substitute jumps and jump targets
  200.  
  201. ___jn    macro    cnd,target,type,depth
  202.     ___jj    n&cnd,target,%&type&depth
  203.     endm
  204.  
  205. ___j    macro    cnd,target,type,depth
  206.     ___jj    cnd,target,%&type&depth
  207.     endm
  208.  
  209. ___l    macro    cnd,target,type,depth
  210.     ___ll    cnd,target,%&type&depth
  211.     endm
  212.  
  213. ___t    macro    target,type,depth
  214.     ___tt    target,%&type&depth
  215.     endm
  216.  
  217. ___makesym    macro    name,num,val
  218. name&num    =    val
  219.     endm
  220.  
  221. ;test to insure you're nesting structures correctly
  222.  
  223. ___test macro    depth,kind
  224.     if    ___depth EQ 0
  225.     .ERR
  226.     %OUT    >>> invalid nesting
  227.     exitm
  228.     endif
  229.     if    kind NE ___type_&depth
  230.     .ERR
  231.     %OUT    >>> invalid nesting
  232.     exitm
  233.     endif
  234.     endm
  235.  
  236. ;find the innermost enclosing loop, if any
  237. ___findloopdepth macro trydepth
  238. ___loopdepth  = trydepth
  239.     if    trydepth LE 0
  240.     .ERR
  241.     %OUT    >>> BREAK/AGAIN not within a loop
  242.     exitm
  243.     endif
  244.     if    ___type_&trydepth NE 2
  245. ___loopdepth = ___loopdepth - 1
  246.     ___findloopdepth %___loopdepth
  247.     endif
  248.     endm
  249.  
  250. ;structured forms
  251.  
  252. _if    macro    op,cnd
  253. ___depth    =    ___depth+1
  254. ___targetcnt    =    ___targetcnt+1
  255.     ___makesym    ___type_,%___depth,1
  256.     ___makesym    ___end_,%___depth,___targetcnt
  257.     ___makesym    ___skip_,%___depth,___targetcnt
  258.     op
  259.     ___jn    cnd,_s_,___skip_,%___depth
  260.     endm
  261.  
  262. _elseif macro    op,cnd
  263.     ___test %___depth,1
  264.     ___j    ,_e_,___end_,%___depth
  265.     ___t    _s_,___skip_,%___depth
  266. ___targetcnt    =    ___targetcnt+1
  267.     ___makesym    ___skip_,%___depth,___targetcnt
  268.     op
  269.     ___jn    cnd,_s_,___skip_,%___depth
  270.     endm
  271.  
  272. _else    macro
  273.     ___test %___depth,1
  274.     ___j    ,_e_,___end_,%___depth
  275.     ___t    _s_,___skip_,%___depth
  276. ___targetcnt    =    ___targetcnt+1
  277.     ___makesym    ___skip_,%___depth,___targetcnt
  278.     endm
  279.  
  280. _endif    macro
  281.     ___test %___depth,1
  282.     ___t    _s_,___skip_,%___depth
  283.     ___t    _e_,___end_,%___depth
  284. ___depth    =    ___depth - 1
  285.     endm
  286.  
  287. _while    macro    op,cnd
  288. ___depth    =    ___depth+1
  289. ___targetcnt    =    ___targetcnt+1
  290.     ___makesym    ___type_,%___depth,2
  291.     ___makesym    ___top_,%___depth,___targetcnt
  292.     ___makesym    ___bottom_,%___depth,___targetcnt
  293.     ___t    _w_,___top_,%___depth
  294.     op
  295.     ifnb    <cnd>
  296.     ___jn    cnd,_u_,___bottom_,%___depth
  297.     endif
  298.     endm
  299.  
  300. _break    macro    op,cnd
  301.     ___findloopdepth  %___depth
  302.     op
  303.     ___j    cnd,_u_,___bottom_,%___loopdepth
  304.     endm
  305.  
  306. _again    macro    op,cnd
  307.     ___findloopdepth  %___depth
  308.     op
  309.     ___j    cnd,_w_,___top_,%___loopdepth
  310.     endm
  311.  
  312. _until    macro    op,cnd
  313.     ___test %___depth,2
  314.     op
  315.     ___jn    cnd,_w_,___top_,%___depth
  316.     ___t    _u_,___bottom_,%___depth
  317. ___depth    =    ___depth - 1
  318.     endm
  319.  
  320. _againcx macro     cnd
  321.     ___test %___depth,2
  322.     ___l    cnd,_w_,___top_,%___depth
  323.     endm
  324.  
  325. _nextcx macro    cnd
  326.     ___test %___depth,2
  327.     ___l    cnd,_w_,___top_,%___depth
  328.     ___t    _u_,___bottom_,%___depth
  329. ___depth    =    ___depth - 1
  330.     endm
  331.  
  332. ; Synonyms for easy use
  333.  
  334. _loop    macro
  335.     _while
  336.     endm
  337.  
  338. _lend    macro
  339.     _until
  340.     endm
  341.  
  342. _wend    macro
  343.     _until
  344.     endm
  345.  
  346. _repeat macro
  347.     _while
  348.     endm
  349.  
  350. _cntnu    macro    op,cnd
  351.     _again    <op>,cnd
  352.     endm
  353.  
  354. ___depth    =    0    ; start _if/_else nesting at level 0
  355. ___targetcnt    =    0    ; start label counter at 0 (allows 65535 "local" labels)
  356.  
  357.     .list
  358.